<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>vue学习</title>
    <script type="text/javascript" src="../assets/js/vue.js"></script>
</head>
<body>
    <h1>vue.directive自定义指令</h1>
    <hr>
    <div id="app">
        <div v-boosli="mycolor">{{message}}</div>
        <p>
            <button @click="add">增加</button>
        </p>
        <p>
            <button onclick="unBind()">解绑</button>
        </p>

    </div>

        <script type="text/javascript">
            // Vue.directive("boosli",function(el,binding){
            //     console.log(el);
            //     console.log(binding)
            //     el.style="color:"+binding.value;

            // });
            //生命周期
            Vue.directive("boosli",{
                bind:function(el,binding){//被绑定
                 el.style="color:"+binding.value;
                    console.log('1 - bind');
                },
                inserted:function(){//绑定到节点
                    console.log('2 - inserted');
                },
                update:function(){//组件更新
                    
                    console.log('3 - update');
                },
                componentUpdated:function(){//组件更新完成
                    console.log('4 - componentUpdated');
                },
                unbind:function(){//解绑
                    console.log('5 - unbind');
                }
            })
           

            var app = new Vue({
                el:'#app',
                data:{
                    message:1,
                    mycolor:'red'
                },
                methods:{
                    add:function(){
                        this.message++;
                    }
                }
            })
            //解绑，需要在vue构造外使用。
            function unBind(){
                app.$destroy();
            }
        </script>
</body>
</html>